package sg.edu.nus.iss.vmcs.system;

/*
 * Copyright 2011 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */

import sg.edu.nus.iss.vmcs.maintenance.MaintenanceController;
import sg.edu.nus.iss.vmcs.machinery.MachineryController;
import sg.edu.nus.iss.vmcs.customer.TransactionController;
import sg.edu.nus.iss.vmcs.util.*;

/**
 * This class represents the control object that is used to set up the 3 panels
 * of VMCS.
 * @version 1.0  09/12/2011
 * @author Team 7S - SE19
 */

public class SimulationController {

	private SimulatorControlPanel scp = null;
/**
 * Reference to the MainController object.
 */	
	public  MainController        mCtrl = null;

/**
 * This constructor creates a new instance of SimulationController.
 * It receives the reference for MainController object.
 * @param ctrl
 */	
	
	public SimulationController(MainController ctrl) {
		mCtrl = ctrl;
		scp = new SimulatorControlPanel(this);
	}

/**
 * This operation returns the reference to the SimulatorControlPanel object.
 * @return Simulator Control Panel
 * 
 * @see SimulatorControlPanel
 */	
	public SimulatorControlPanel getSimulatorControlPanel() {
		return (scp);
	}

/**
 * This operation displays the Simulator Control Panel.
 */	
	public void displaySimulatorControlPanel() {
		scp.display();
	}

/**
 * This operation will instruct the Main Controller to close down.
 */	
	public void stop() {
		mCtrl.closeDown();
	}

/**
 * This operation will instruct all four panels of the VMCS to close down when
 * instructed by the Main Controller.
 */	
	public void closeDown() {
		scp.closeDown();
	}

/**
 * This operation is triggered when the Begin Simulation Button is pressed on the
 * Simulator Control Panel. It will start the simulation of VMCS by activating
 * the three panel buttons namely Activate Customer Panel Button, Activate Maintainer
 * Panel Button, Activate Machinery Simulator Button.
 */	
	public void start() {
		scp.setSimulationActive(true);
		scp.setActive(SimulatorControlPanel.SIMUL_BEGIN, false);
	}

/**
 * This operation enables the Begin Simulation Button and disable the other
 * buttons if FALSE is passed. If TRUE is passed the Begin Simulation Button is
 * disabled and the other buttons of the Simulator Control Panel are enabled. 
 * @param vl value that sets the Simulator Control Panel Buttons (Enabled/Disabled)
 */	
	public void setSimulationActive(boolean vl) {
		scp.setSimulationActive(vl);
	}
	
/**
 * This operation sets up the Machinery Simulator Panel.
 * This will be achieved as follows:
 * 1  Deactivate the Activate Machinery Simulator Button.
 * 2  Display Machinery Simulator Panel with intial values set.
 * 3  Deactivate the panel.
 */
	public void setupSimulator() {
		//MaintenanceController maintenanceCtrl;
		//maintenanceCtrl = mCtrl.getMaintenanceController();
		MachineryController machCtrl;

		machCtrl = mCtrl.getMachineryController();
		scp.setActive(SimulatorControlPanel.ACT_MACHINERY, false);
		try {
			// activate when not login
			// always display the door locked; isOpen false
			machCtrl.displayMachineryPanel();

			// display drink stock;
			machCtrl.displayDrinkStock();

			// display coin quantity;
			machCtrl.displayCoinStock();

			machCtrl.displayDoorState();
		} catch (VMCSException e) {
			System.out.println("SimulationController.setupSimulator:" + e);
		}
	}

/**
 * This operation sets up the Maintenance Panel.
 * Set-up the Maintenance Panel. This will be acheived as follows:
 * 1  Send a message to deactivate the Activate Maintainer Panel Button.
 * 2  Send messages to instruct all its constituent objects to display 
 * themselves, and also instruct them all, except for the Password Box 
 * to become deactivated.
 */	
	public void setupMaintainer() {
		MaintenanceController mctrl;
		mctrl = mCtrl.getMaintenanceController();
		scp.setActive(SimulatorControlPanel.ACT_MAINTAINER, false);
		mctrl.displayMaintenancePanel();
	}

/**
 * This operation sets up the Customer Panel.
 * Set-up the Customer Panel. This will be acheived as follows:
 * 1  Send a message to deactivate the Activate Customer Panel Button.
 * 2  Send a message to the Customer Panel instructing it to 
 *    display all its constituent interface objects.
 * 3  Display the current values for out of stock brands and prices.
 * 4  Activate the No Change Available Display (if necessary).
 */	
	public void setupCustomer() {
		TransactionController tctrl;
		tctrl = mCtrl.getTransactionController();
		scp.setActive(SimulatorControlPanel.ACT_CUSTOMER, false);
		tctrl.displayCustomerPanel();
	}

/**
 * This operation returns the reference for the MainController Object
 * @return Main Controller
 * 
 * @see MainController
 */	
	public MainController getMainController() {
		return mCtrl;
	}

}
